package com.sgb.kjwl.view.ui.adapter.pricecheck;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pricecheck.SupplierEntitiy;
import com.sgb.kjwl.utils.DisplayUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author Administrator
 */
public class SupplierDataAdapter extends BaseRecycleAdapter<SupplierEntitiy> {
    private ImageView deleteSupplier;
    private TextView supplierText;
    private Drawable drawableVip;
    private int drawablePadding;

    public SupplierDataAdapter(Context context, List<SupplierEntitiy> datas) {
        super(context, R.layout.item_supplierview, datas);
        initVipDrawable();
    }

    private void initVipDrawable() {
        this.drawableVip = ContextCompat.getDrawable(context, R.mipmap.ic_vip);
        this.drawableVip.setBounds(0, 0, DisplayUtil.convertDpToPixel(context, 18), DisplayUtil.convertDpToPixel(context, 15));
        this.drawablePadding = DisplayUtil.convertDpToPixel(context, 5);
    }

    @Override
    public void convert(ItemViewHolder holder, SupplierEntitiy supplierEntitiy) {
        holder.setBinding(BR.viewModel, supplierEntitiy);
        deleteSupplier = (ImageView) holder.itemView.findViewById(R.id.deleteSupplier);
        supplierText = (TextView) holder.itemView.findViewById(R.id.supplierText);
        showSupplierVipIcon(supplierText, supplierEntitiy);
        deleteSupplier.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (datas != null) {
                    mDeleteSupplierListener.onDelete(supplierEntitiy);
                }
            }
        });
    }

    private void showSupplierVipIcon(TextView tvCompany, SupplierEntitiy entitiy) {
        if (entitiy != null) {
            if (entitiy.getFlag() == 1) {
                tvCompany.setCompoundDrawables(drawableVip, null, null, null);
                tvCompany.setCompoundDrawablePadding(drawablePadding);
            } else {
                tvCompany.setCompoundDrawables(null, null, null, null);
            }
        }
    }

    /***
     *     删除的回调
     */
    public interface OnDeleteSupplierListener {
        void onDelete(SupplierEntitiy supplierEntitiy);

    }

    public void setOnSupplierDeleteListener(OnDeleteSupplierListener listener) {
        mDeleteSupplierListener = listener;
    }

    private OnDeleteSupplierListener mDeleteSupplierListener;
}
